// 基础类型定义

// 从exokernel导入的类型
pub type CapabilityId = u64;
pub type PhysicalAddress = u64;
pub type VirtualAddress = u64;
pub type DriverId = u64;

// 资源类型枚举
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ResourceType {
    Memory = 1,
    Cpu = 2,
    Io = 3,
    Interrupt = 4,
}

// 内存权限结构体
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MemoryPermissions {
    pub read: bool,
    pub write: bool,
    pub execute: bool,
    _reserved: u16, // 保留字段以确保ABI兼容性
}

impl Default for MemoryPermissions {
    fn default() -> Self {
        MemoryPermissions {
            read: false,
            write: false,
            execute: false,
            _reserved: 0,
        }
    }
}

impl MemoryPermissions {
    // 创建具有读取权限的内存权限
    pub fn read_only() -> Self {
        MemoryPermissions {
            read: true,
            write: false,
            execute: false,
            _reserved: 0,
        }
    }
    
    // 创建具有读写权限的内存权限
    pub fn read_write() -> Self {
        MemoryPermissions {
            read: true,
            write: true,
            execute: false,
            _reserved: 0,
        }
    }
    
    // 创建具有执行权限的内存权限
    pub fn read_execute() -> Self {
        MemoryPermissions {
            read: true,
            write: false,
            execute: true,
            _reserved: 0,
        }
    }
    
    // 创建具有全部权限的内存权限
    pub fn read_write_execute() -> Self {
        MemoryPermissions {
            read: true,
            write: true,
            execute: true,
            _reserved: 0,
        }
    }
}